import 'package:flutter/foundation.dart';

class DeviceUtil {

  static bool get isDesktop => !isWeb && (isWindows || isLinux || isMacOS);
  static bool get isMobile => isAndroid || isIOS;

  //这里不要使用Flutter自带的Platform.isXXX来判断是什么平台,在web使用时出现了Unsupported operation: Platform._operatingSystem的报错
  static bool get isWeb => kIsWeb;
  static bool get isWindows => (defaultTargetPlatform == TargetPlatform.windows);
  static bool get isLinux => (defaultTargetPlatform == TargetPlatform.linux);
  static bool get isMacOS => (defaultTargetPlatform == TargetPlatform.macOS);
  static bool get isAndroid => (defaultTargetPlatform == TargetPlatform.android);
  static bool get isFuchsia => (defaultTargetPlatform == TargetPlatform.fuchsia);
  static bool get isIOS => (defaultTargetPlatform == TargetPlatform.iOS);

  static AppPlatform getPlatform(){
    if(isAndroid){
      return AppPlatform.android;
    }else if(isIOS){
      return AppPlatform.iOS;
    }else if(kIsWeb){
      return AppPlatform.web;
    }else if(isWindows){
      return AppPlatform.windows;
    }else if(isMacOS){
      return AppPlatform.macOS;
    }else if(isFuchsia){
      return AppPlatform.fuchsia;
    }else if(isLinux){
      return AppPlatform.linux;
    }
    return AppPlatform.android;
  }

}

enum AppPlatform {
  android,
  fuchsia,
  iOS,
  linux,
  macOS,
  windows,
  web,
}